home *** CD-ROM | disk | FTP | other *** search
- /*
- ** WINFTP.C
- **
- ** WINFTP Client.
- **
- ** Last modified: 3/14/1999
- */
-
- #include <windows.h>
- #include <winsock.h>
- #include "fce.h"
- #include "connect.h"
- #include "files.h"
- #include "info.h"
- #include "message.h"
-
- #ifdef WIN32
- #define USE_INS HINSTANCE
- #define USE_PTR PSTR
- #else
- #define USE_INS HANDLE
- #define USE_PTR LPSTR
- #endif
-
- #define BS 8
- #define LF 10
- #define CR 13
- #define ESC 27
-
- #define MAX_BUF 2048
- #define RX_BUF MAX_BUF
- #define TX_BUF 512
- #define MAX_STR 64
-
- #define POPWIDTH 140
- #define POPHEIGHT 50
-
- /* private */
-
- static USE_INS hInstance;
- static RECT MainRect;
- static char Temp[MAX_STR+8];
-
- /* globals */
-
- HWND hMainWnd; /* main window handle */
- HWND hInfoWnd; /* popup handle */
- HCURSOR ArrowCursor; /* arrow cursor */
- HCURSOR WaitCursor; /* hour glass cursor */
- int ConnectStatus = FALSE;
- int MasterAbort = FALSE;
-
- LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
-
- void Message(LPSTR Message)
- {MessageBox(NULL,Message,(LPSTR)"INFO", MB_TASKMODAL|MB_ICONEXCLAMATION);
- }
-
- int AskUser(LPSTR Message)
- {return MessageBox(NULL,Message,(LPSTR)"CONFIRM",
- MB_TASKMODAL|MB_ICONQUESTION|MB_OKCANCEL);
- }
-
- void ShowError(int Code)
- {char Temp1[80];
- char Temp2[100];
- fceErrorText(0,Code,(LPSTR)Temp1,80);
- wsprintf((LPSTR)Temp2, "ERROR %d: %s", Code, Temp1);
- Message((LPSTR)Temp2);
- SetCursor(ArrowCursor);
- }
-
- int IsConnected(void)
- {if(fceGetInteger(0,FCE_GET_CONNECT_STATUS)) return TRUE;
- Message("Connection to FTP server lost");
- return FALSE;
- }
-
- /* WinMain */
-
- #ifdef WIN32
- int WINAPI
- #else
- int PASCAL
- #endif
- WinMain(USE_INS hInst, USE_INS hPrevInstance,
- USE_PTR szCmdLine, int nCmdShow)
- {WNDCLASS wc1, wc2;
- MSG msg;
- BOOL Result;
- if(!hPrevInstance)
- {/* register main window class */
- wc1.style = CS_HREDRAW | CS_VREDRAW;
- wc1.lpfnWndProc = MainWndProc;
- wc1.cbClsExtra = 0;
- wc1.cbWndExtra = 0;
- wc1.hInstance = hInst;
- wc1.hIcon = LoadIcon(hInst, "HostIcon");
- wc1.hCursor = NULL;
- wc1.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
- wc1.lpszMenuName = "HostMenu";
- wc1.lpszClassName = "HostWClass";
- Result = RegisterClass(&wc1);
- if(!Result) return FALSE;
-
- /* register popup window class */
- wc2.style = CS_HREDRAW | CS_VREDRAW | CS_PARENTDC;
- wc2.lpfnWndProc = InfoWndProc;
- wc2.cbClsExtra = 0;
- wc2.cbWndExtra = 0;
- wc2.hInstance = hInst;
- wc2.hIcon = NULL;
- wc2.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc2.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
- wc2.lpszMenuName = NULL;
- wc2.lpszClassName = "InfoWClass";
- Result = RegisterClass(&wc2);
- if(!Result) return FALSE;
- }
- /* create main window */
- hInstance = hInst;
- hMainWnd = CreateWindow(
- "HostWClass", "WINFTP", WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT,
- 250, 130,
- NULL, NULL,
- hInstance, NULL);
- ShowWindow(hMainWnd, nCmdShow);
- UpdateWindow(hMainWnd);
-
- /* window control loop */
-
- while(GetMessage(&msg,NULL,0,0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (msg.wParam);
- } /* end WinMain */
-
- #ifdef WIN32
- LRESULT CALLBACK
- #else
- long FAR PASCAL
- #endif
- MainWndProc(HWND hWindow,UINT iMsg,WPARAM wParam,LPARAM lParam)
- {int Code;
- HMENU hMenu;
- static int Version;
- HDC hDC;
- PAINTSTRUCT ps;
- #ifdef WIN32
- #else
- static FARPROC lpfnConnectDlgProc;
- static FARPROC lpfnFilesDlgProc;
- #endif
- static char Msg1[] = "Welcome to WINFTP";
- static char Msg2[] = "Choose 'Connection' to connect.";
- static char Msg3[] = "Choose 'Files' after connecting.";
- /* begin */
- hMainWnd = hWindow;
- switch (iMsg)
- {case WM_CREATE:
- /* create popup Info window */
- GetWindowRect(hMainWnd,&MainRect);
- hInfoWnd = CreateWindow(
- "InfoWClass", "Info",
- WS_POPUP | WS_BORDER | WS_CAPTION | WS_THICKFRAME,
- 12, 12,
- POPWIDTH, POPHEIGHT,
- hMainWnd, NULL,
- hInstance, NULL);
- UpdateWindow(hInfoWnd);
-
- /* create cursors */
- ArrowCursor = LoadCursor(NULL, IDC_ARROW);
- WaitCursor = LoadCursor(NULL, IDC_WAIT);
- SetCursor(ArrowCursor);
- #ifdef WIN32
- #else
- /* create thunk for Win16 */
- lpfnConnectDlgProc = MakeProcInstance(ConnectDlgProc,hInstance);
- lpfnFilesDlgProc = MakeProcInstance(FilesDlgProc,hInstance);
- #endif
- /* gray out "Files" on menu bar */
- hMenu = GetMenu(hMainWnd);
- EnableMenuItem(hMenu,MSG_FILES,MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
- DrawMenuBar(hMainWnd);
- /* attach FCE */
- Code = fceAttach(1);
- if(Code<0)
- {Message("fceAttach fails");
- break;
- }
- /* define LOG file */
- *Temp = '\0';
- /* get FCE version */
- Version = (int) fceGetInteger(0,FCE_GET_VERSION);
- break;
-
-
- case WM_PAINT:
- hDC = BeginPaint(hMainWnd, &ps);
- //SetMapMode(hDC,MM_ANISOTROPIC);
- //SelectObject(hDC, GetStockObject(OEM_FIXED_FONT) );
-
- #ifdef WIN32
- wsprintf((LPSTR)Temp,"FCE32 Version %1d.%1d.%1d",
- 0x0f&(Version>>8),0x0f&(Version>>4),0x0f&Version);
- #else
- wsprintf((LPSTR)Temp,"FCE16 Version %1d.%1d.%1d",
- 0x0f&(Version>>8),0x0f&(Version>>4),0x0f&Version);
- #endif
- TextOut(hDC,5, 5,(LPSTR)Temp,lstrlen(Temp));
- TextOut(hDC,15,25,(LPSTR)Msg1,lstrlen(Msg1));
- TextOut(hDC,15,40,(LPSTR)Msg2,lstrlen(Msg2));
- TextOut(hDC,15,55,(LPSTR)Msg3,lstrlen(Msg3));
- EndPaint(hMainWnd,&ps);
- break;
-
-
- case WM_COMMAND:
- switch(wParam)
- {
- case MSG_CONNECT:
- #ifdef WIN32
- DialogBox(hInstance, "ConnectBox", hMainWnd, ConnectDlgProc);
- #else
- DialogBox(hInstance, "ConnectBox", hMainWnd, lpfnConnectDlgProc);
- #endif
- /* enable "files" if connected */
- if(ConnectStatus)
- {hMenu = GetMenu(hMainWnd);
- EnableMenuItem(hMenu,MSG_FILES,MF_BYCOMMAND|MF_ENABLED);
- EnableMenuItem(hMenu,MSG_CONNECT,MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
- DrawMenuBar(hMainWnd);
- }
- return 0;
-
- case MSG_FILES:
- #ifdef WIN32
- DialogBox(hInstance, "FilesBox", hMainWnd, FilesDlgProc);
- #else
- DialogBox(hInstance, "FilesBox", hMainWnd, lpfnFilesDlgProc);
- #endif
- if(!ConnectStatus)
- {hMenu = GetMenu(hMainWnd);
- EnableMenuItem(hMenu,MSG_CONNECT,MF_BYCOMMAND|MF_ENABLED);
- EnableMenuItem(hMenu,MSG_FILES,MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
- DrawMenuBar(hMainWnd);
- }
- return 0;
-
- case MSG_EXIT:
- if(ConnectStatus) fceClose(0);
- fceRelease();
- DestroyWindow(hMainWnd);
- break;
- }
- break;
-
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
-
- default:
- return (DefWindowProc(hMainWnd, iMsg, wParam, lParam));
- }
- return 0;
- }
-
-